package cn.tedu.web.mapper;

import cn.tedu.web.entity.Category;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author issen
 * @since 2021-09-23
 */
@Mapper
public interface CategoryMapper extends BaseMapper<Category> {
    // 检测分类名称是否存在
    @Select("SELECT COUNT(1) FROM `ec_category` WHERE `name` = #{u}")
    public Boolean exists(@Param("u") String name);

    // 新增分类
    @Insert("INSERT INTO `ec_category` (`name`)VALUES(#{n})")
    public Integer insert(@Param("n") String name);

    // 查询所有分类
    @Select("SELECT `id`, `name` FROM `ec_category` ORDER BY id")
    public List<Category> findAll();

    // 根据ID查询分类的名称
    @Select("SELECT `name` FROM `ec_category` WHERE `id` = #{id}")
    public String findNameById(@Param("id") Integer integer);

    /**
     * 删除指定的分类
     * 
     * @param id
     * @return
     */
    @Delete("delete FROM `ec_category` WHERE `id` = #{id}")
    public Integer delete(@Param("id") Integer id);
}
